﻿using System;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraBars;
using System.Configuration;
using ERP.form;
namespace HoangHuy.form
{
    public partial class frmMain : XtraForm
    {
       
        public frmMain()
        {
            InitializeComponent();
        }
     
        #region Parameter
        string strCurrentControlVisible = string.Empty;        
        string skinMask = "Giao Diện: ";
        #endregion

        #region Functions

        public void ShowControl(XtraForm frm,string header)
        {            
            if (!FindControl(frm.Name))
            {
                VisibleAllControlInPanelInfo();
                frm.FormBorderStyle = FormBorderStyle.None;
                frm.TopLevel = false;
                //frm.MdiParent = this;
                frm.Dock = DockStyle.Fill;                
                panelInfo.Controls.Add(frm);
                frm.Show();
                barSubCloseCurrenForm.Enabled = true;
                strCurrentControlVisible = frm.Name;
                lblHeader.Text = header;            
            }            
        }

        private bool FindControl(string ControlName)
        {
            Control[] _control = panelInfo.Controls.Find(ControlName,true);
            if (_control.Length > 0)
            {                
                return true;
            }
            else return false;            
        }

        private void VisibleAllControlInPanelInfo()
        {
            if (strCurrentControlVisible != string.Empty)
               ((XtraForm)panelInfo.Controls.Find(strCurrentControlVisible, true)[0]).Close();
        }

        #endregion
        
        #region Menu Event
        private void barCheckNavigate_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (((BarCheckItem)e.Item).Checked)
            {
                dockPanel1.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Visible;
            }
            else if (!((BarCheckItem)e.Item).Checked)
            {
                dockPanel1.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden;
            }
        }

        private void barSubExit_ItemClick(object sender, ItemClickEventArgs e)
        {
            Application.Exit();
        }

        private void barSubCloseCurrenForm_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (strCurrentControlVisible != string.Empty)
            {
                //panelInfo.Controls.RemoveByKey(strCurrentControlVisible);
                ((XtraForm)panelInfo.Controls.Find(strCurrentControlVisible, true)[0]).Close();
                barSubCloseCurrenForm.Enabled = false;
                lblHeader.Text = "quản lý tồn kho";
                strCurrentControlVisible = string.Empty;
            }
        }

        #endregion

        #region Events

        private void FrmMain_Load(object sender, EventArgs e)
        {
            DevExpress.UserSkins.OfficeSkins.Register();
            DevExpress.UserSkins.BonusSkins.Register();
            
            foreach (DevExpress.Skins.SkinContainer cnt in DevExpress.Skins.SkinManager.Default.Skins)
            {
                BarButtonItem item = new BarButtonItem(barManager1, skinMask + cnt.SkinName);
                barSubLookandfeel.AddItem(item);
                item.ItemClick += OnSkinClick;
            }
            DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle(DevExpress.Skins.SkinManager.Default.Skins["Lilian"].SkinName);
        }
        
        void OnSkinClick(object sender, ItemClickEventArgs e)
        {
            string skinName = e.Item.Caption.Replace(skinMask, "");
            DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle(skinName);
            barManager1.GetController().PaintStyleName = "Skin";
            barSubLookandfeel.Caption = e.Item.Caption;
            barSubLookandfeel.Hint = barSubLookandfeel.Caption;
            barSubLookandfeel.ImageIndex = -1;
        }

        private void panelInfo_ControlRemoved(object sender, ControlEventArgs e)
        {
            lblHeader.Text = "quản lý tồn kho";
            strCurrentControlVisible = string.Empty;
        }

        private void dockPanel1_ClosedPanel(object sender, DevExpress.XtraBars.Docking.DockPanelEventArgs e)
        {
            barCheckNavigate.Checked = false;
        }
        #endregion       

        private void navBIDanhSachMatHang_clicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            frmDanhSachMatHang frm = new frmDanhSachMatHang();
            ShowControl(frm, navBIDanhSachMatHang.Caption);
        }

        private void navBIDanhSachLoaiHang_clicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            frmDanhSachLoaiHang frm = new frmDanhSachLoaiHang();
            ShowControl(frm, navBIDanhSachMatHang.Caption);
        }

        private void barButtonItem1_ItemClick(object sender, ItemClickEventArgs e)
        {

        }

        private void barButtonItem2_ItemClick(object sender, ItemClickEventArgs e)
        {

        }

        private void barButtonItem3_ItemClick(object sender, ItemClickEventArgs e)
        {

        }
    }
}
